﻿
$(document).ready(function () {
    $("input:submit,.ui-widget > a").button();
    $("button").button();
    $(".buttonset").buttonset();
    $("#tabs").tabs({
        show: function (e, ui) {
            getTabContent(ui.index + 1);
        }
    });
    $("#confirm-dialog").dialog({ autoOpen: false });
    $(".delete-button").live("click", function () {
        var url = this.href;
        var targetclicked = this;
        $("#confirm-dialog").dialog({
            autoOpen: true,
            width: 300,
            modal: true,
            buttons: {
                "Đồng ý": function () {
                    $.ajax({
                        url: url,
                        type: "DELETE",
                        success: function (data) {
                            if (data == "")
                                $(targetclicked).parent().parent().hide();
                            else
                                alert(data);
                        }
                    });
                    $(this).dialog("close");
                },
                "Hủy bỏ": function () {
                    $(this).dialog("close");
                }
            }
        });
        return false;
    });
    $(".uploadImg").live("click", function () {
        $("#upload-dialog").dialog({
            autoOpen: true,
            width: 450,
            modal: true,
            buttons: {
                "Đóng Lại": function () {
                    $(this).dialog("close");

                }
            }
        });

        return false;

    });
    $("#dialog-form").dialog({
        autoOpen: false,
        width: 350,
        modal: true,
        buttons: {
            "Tạo mới": function () { $(this).dialog("close"); },
            "Hủy bỏ": function () { $(this).dialog("close"); }
        }
    });
    $("#create-user").click(function () {
        $("#dialog-form").dialog("open");
    });


});
function getTabContent(index) {
    var targetId = "#tabs-" + index;
    var ajaxLoading = "<img src='../../Content/ajax-loader.gif' width='28px' height='28px' align='left'/>";
    $(targetId).html("<p>" + ajaxLoading + " Đang tải...</p>");
    var url;
    switch (index) {
        case 1: url = "/JPost/SavedPosts"; break;
        case 2: url = "/JPost/PendingPosts";  break;
        case 3: url = "/JPost/PublishedPosts";  break;
        case 4: url = "/JPost/RejectedPosts";  break;
    }
    $.get(url, null, function (result) {
        $(targetId).html(result);
    });
    return false;
}

